import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
import {freightForwarderType} from '../Enum';
const baseUrl = '/parts/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化备件交货单状态跟踪信息'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询备件交货单状态跟踪信息'
});
const exportDesc = formatMessage({
    id: 'api.exportDesc',
    defaultMessage: '导出备件交货单状态跟踪信息'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/deliveryOrderTrack/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify({
        ...pageOption,
        type: freightForwarderType.货代公司
    });
    return request(`${baseUrl}/deliveryOrderTracks?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 导出
export const exports = pageOption => {
    const queryString = stringify({
        ...pageOption,
        type: freightForwarderType.货代公司
    });
    return request(`${baseUrl}/deliveryOrderTracks/export?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
